<template>
    <div>
        <h1>投资项目编辑</h1>
        <table class="table table-bordered table-hover table-striped" >
        <tr>
            <td>投资项目名称 </td>
            <td><input type="text" v-model="I_Name" placeholder="请输入投资项目名称"/></td>
        </tr>
        <tr>
            <td>投资总金额 </td>
            <td><input type="text" v-model="I_Budget" placeholder="请输入投资总金额"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="Upd">修改</button>
            </td>           
        </tr>

    </table>

    </div>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';

import { useRoute } from 'vue-router';

const route = useRoute();

console.log(route.params.id);

const I_Name = ref('');
const I_Budget = ref('');

onMounted(()=>{
    Updshow();
})

const Updshow = ()=>{
    axios({
        method:'get',
        url:'http://localhost:57969/api/Invest/UpdShowInvestinfo',
        params:{
            id:route.params.id
        }
    })
    .then(res=>{
        console.log(res.data);
        I_Name.value = res.data.I_Name;
        I_Budget.value = res.data.I_Budget;
    })
    .catch(err=>{
        console.log(err);
    })
}


const Upd = () => {
    if (I_Name.value == "" ) {
        alert("请输入投资项目名称");
        return;
    }

    //投资总金额大于0小于1000000
    if (Number(I_Budget.value) <= 0 || Number(I_Budget.value) > 1000000) {
        alert("投资总金额必须大于0小于1000000");
        return;
    }

    axios({
        method: "post",
        url: "http://localhost:57969/api/Invest/UpdInvestinfo",
        data: {
            I_Name: I_Name.value,
            I_Budget: I_Budget.value,
            I_Id: route.params.id
        }

    })
    .then(res => {
        if(res.data>0)
        {
            alert("修改成功");
        }
        else
        {
            alert("修改失败");
        }
            
    })     
}
</script>
